import pygame
from settings import *

class Button:
    def __init__(self, x, y, w, h, text):
        self.rect = pygame.Rect(x, y, w, h)
        self.text = text
        self.color = black

    def draw(self, surf):
        pygame.draw.rect(surf, self.color, self.rect)
        draw_text(surf, self.text, 30, self.rect.centerx, self.rect.centery)

    def is_clicked(self, pos):
        return self.rect.collidepoint(pos)

def draw_text(surf, text, size, x, y):
    font = pygame.font.Font("simhei.ttf", size)
    text_surface = font.render(text, True, white)
    text_rect = text_surface.get_rect()
    text_rect.center = (x, y)
    surf.blit(text_surface, text_rect)
